package com.atguigu.yygh.hosp.controller.user;

import com.atguigu.yygh.hosp.service.DepartmentService;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.result.R;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*==========================================
      时 间:   2022-04-22
      讲 师:   刘  辉
      描 述:   尚硅谷教学团队
 ==========================================*/
@RestController
@RequestMapping("/user/hosp")
public class UserHospitalController {


    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private DepartmentService departmentService;

    //根据医院编号获取该医院下的所有科室信息
    @GetMapping("/departments/{hoscode}")
    public R getDepartmentList(@PathVariable String hoscode){
        List<DepartmentVo> departmentList = departmentService.getDepartmentList(hoscode);
        return R.ok().data("departmentList",departmentList);
    }


    //根据医院编号获取医院详情信息
    @GetMapping("/detail/{hoscode}")
    public R getHospitalDetail(@PathVariable String hoscode){
       Hospital hospital= hospitalService.getPackageHosptialInfo(hoscode);
       return R.ok().data("hospital",hospital);
    }


    @GetMapping("/list/{name}")
    public R getHospitalListByName(@PathVariable String name){
       List<Hospital> hospitalList= hospitalService.findByHosnameLike(name);
       return R.ok().data("list",hospitalList);
    }


    //@RequestBody: null 值
    //@RequestBody: date 时间
    @GetMapping("/list")
    public R getHospitalList(HospitalQueryVo hospitalQueryVo){
        Page<Hospital> hospitalPage = hospitalService.getHospitalPage(1, 100000000, hospitalQueryVo);
        return R.ok().data("list",hospitalPage.getContent());
    }



}
